package com.jessechanrui.template.common.template.auth.config;

import com.jessechanrui.template.common.template.auth.config.interceptor.AuthInterceptor;
import com.jessechanrui.template.common.template.auth.config.interceptor.MdcInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author chenrui
 * @version 1.0
 * @description AuthConfig
 * @date 2025/4/30
 */
@Configuration
public class AuthConfigConfiguration implements WebMvcConfigurer {

    @Autowired
    private AuthConfigProperties authConfigProperties;

    @Autowired
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                .excludePathPatterns(
                        "/error",
                        "/swagger-ui/**",
                        "/v3/api-docs/**",
                        "/swagger-resources/**")
                .excludePathPatterns(authConfigProperties.getExcludePaths());

        //日志追踪ID
        registry.addInterceptor(new MdcInterceptor()).addPathPatterns("/**");

    }

}
